package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"registration/models"
)

type RegistrationController struct {
	beego.Controller
}
type Count struct {
	Data  interface{} `json:"data"`
	Count int64       `json:"count"`
}

func (c *RegistrationController) List() {
	c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
	page, _ := c.GetInt("page", 1)
	pageSize, _ := c.GetInt("pageSize", 10)

	i := page - 1*pageSize
	var dockers []models.Docker

	var count int64
	models.DB.Model(&models.Docker{}).Count(&count)
	models.DB.Debug().Offset(i).Limit(pageSize).Find(&dockers)
	c.Data["json"] = map[string]interface{}{
		"code": 200,
		"mes":  "查询成功",
		"data": Count{
			Data:  dockers,
			Count: count,
		},
	}
	c.ServeJSON()
	return
}
